package com.yike.user.controller;

import com.yike.common.api.ApiResult;
import com.yike.common.base.BaseController;
import com.yike.common.enums.OperationLogType;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.pagination.Paging;
import com.yike.user.param.*;
import com.yike.user.service.PlatformWithdrawalService;
import com.yike.user.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 代理商提现申请表 控制器
 *
 * @author Sakura
 * @since 2024-11-04
 */
@Slf4j
@RestController
@RequestMapping("/platform/withdrawal")
@Module("user")
@Api(value = "平台提现API", tags = {"平台提现管理"})
public class PlatformWithdrawalController extends BaseController {

    @Autowired
    private PlatformWithdrawalService platformWithdrawalService;

    @GetMapping("/getWithdrawalRate")
    @OperationLog(name = "获取提现费率", type = OperationLogType.ADD)
    @ApiOperation(value = "获取提现费率", response = ApiResult.class)
    public ApiResult<String> getWithdrawalRate() throws Exception {
        String rate = platformWithdrawalService.getWithdrawalRate();
        return ApiResult.ok(rate);
    }

    @PostMapping("/setWithdrawalRate")
    @OperationLog(name = "设置提现费率", type = OperationLogType.ADD)
    @ApiOperation(value = "设置提现费率", response = ApiResult.class)
    public ApiResult<Boolean> setWithdrawalRate(@RequestBody SetWithdrawalParam setWithdrawalParam) throws Exception {
        boolean flag = platformWithdrawalService.setWithdrawalRate(setWithdrawalParam);
        return ApiResult.result(flag);
    }

    @PostMapping("/check")
    @OperationLog(name = "提现审核", type = OperationLogType.ADD)
    @ApiOperation(value = "提现审核", response = ApiResult.class)
    public ApiResult<Boolean> withdrawalCheck(@RequestBody AgentWithdrawalCheckParam agentWithdrawalCheckParam) throws Exception {
        boolean flag = platformWithdrawalService.withdrawalCheck(agentWithdrawalCheckParam);
        return ApiResult.result(flag);
    }

    @PostMapping("/batchCheck")
    @OperationLog(name = "批量审核", type = OperationLogType.ADD)
    @ApiOperation(value = "批量审核", response = ApiResult.class)
    public ApiResult<Boolean> batchCheck(@RequestBody BatchWithdrawalCheckParam batchWithdrawalCheckParam) throws Exception {
        boolean flag = platformWithdrawalService.batchCheck(batchWithdrawalCheckParam);
        return ApiResult.result(flag);
    }

    /**
     * 获取代理商提现申请表详情
     */
    @GetMapping("/getWithdrawalApplyInfo/{id}")
    //@OperationLog(name = "提现申请详情", type = OperationLogType.INFO)
    @ApiOperation(value = "提现申请详情", response = PlatformWithdrawalApplyVo.class)
    public ApiResult<PlatformWithdrawalApplyVo> getAgentWithdrawalApply(@PathVariable("id") Long id) throws Exception {
        PlatformWithdrawalApplyVo agentWithdrawalApplyVo = platformWithdrawalService.getPlatformWithdrawalApply(id);
        return ApiResult.ok(agentWithdrawalApplyVo);
    }


    /**
     * 代理商提现申请表分页列表
     */
    @PostMapping("/getWithdrawalApplyList")
    //@OperationLog(name = "提现申请分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "提现申请分页列表", response = PlatformWithdrawalApplyVo.class)
    public ApiResult<Paging<PlatformWithdrawalApplyVo>> getAgentWithdrawalApplyPageList(@Validated @RequestBody PlatformWithdrawalApplyPageParam platformWithdrawalApplyPageParam) throws Exception {
        Paging<PlatformWithdrawalApplyVo> paging = platformWithdrawalService.getPlatformWithdrawalApplyPageList(platformWithdrawalApplyPageParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/getWithdrawalAccountList")
    //@OperationLog(name = "提现账号分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "提现账号分页列表", response = PlatformWithdrawalVo.class)
    public ApiResult<Paging<PlatformWithdrawalVo>> getWithdrawalAccountList(@Validated @RequestBody PlatformWithdrawalPageParam platformWithdrawalPageParam) throws Exception {
        Paging<PlatformWithdrawalVo> paging = platformWithdrawalService.getWithdrawalAccountList(platformWithdrawalPageParam);
        return ApiResult.ok(paging);
    }

    @GetMapping("/getWithdrawalInfo/{id}")
    //@OperationLog(name = "提现申请详情", type = OperationLogType.INFO)
    @ApiOperation(value = "提现账号详情", response = PlatformWithdrawalVo.class)
    public ApiResult<PlatformWithdrawalVo> getWithdrawalInfo(@PathVariable("id") Long id) throws Exception {
        PlatformWithdrawalVo platformWithdrawalVo = platformWithdrawalService.getWithdrawalInfo(id);
        return ApiResult.ok(platformWithdrawalVo);
    }

}

